package com.aaa.service.mht.impl;


import com.aaa.dao.mht.TMhtSurveyMapper;
import com.aaa.entity.MyPage;
import com.aaa.entity.mht.TMhtSurvey;
import com.aaa.service.mht.TMhtSurveyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘鸿飞
 * @version 1.0.0
 * @ProjectName qy160-9
 * @date 2022/11/8 13:51
 */
@Service
public class TMhtSurveyServiceImpl implements TMhtSurveyService {
    @Autowired
    private TMhtSurveyMapper tMhtSurveyMapper;

    @Override
    public boolean addSurvey(TMhtSurvey tMhtSurvey) {
        int insert = -1;
        List<TMhtSurvey> select = tMhtSurveyMapper.select(tMhtSurvey);
        if (select.size()>0){
            insert = tMhtSurveyMapper.updateByPrimaryKeySelective(tMhtSurvey);
        }else {
            insert = tMhtSurveyMapper.insertSelective(tMhtSurvey);
        }
        return insert>0;
    }

    @Override
    public PageInfo querySurvey(MyPage myPage, TMhtSurvey tMhtSurvey) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        return new PageInfo(tMhtSurveyMapper.selectquerySurvey(tMhtSurvey));
    }

    @Override
    public boolean updSurvey(TMhtSurvey tMhtSurvey) {
        int i = tMhtSurveyMapper.updateByPrimaryKeySelective(tMhtSurvey);
        return i>0;
    }

    @Override
    public boolean delSurvey(TMhtSurvey tMhtSurvey) {
        int i = tMhtSurveyMapper.deleteSurvey(tMhtSurvey);
        return i>0;
    }
}
